<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('批量变更购买人')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-record-add" enctype="multipart/form-data">
        <h4 class="form-header h4" ></h4>
        <div class="row">

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">点击上传SN号：</label>
                <div class="col-sm-8">
                    <span class="btn btn-white btn-file">
                        <input id="files" type="file" name="file"  accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
                    </span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">原购买人：</label>
                <div class="col-sm-8">
                    <input name="beforAgent" onclick="selectAgent2()" class="form-control" id="beforAgent" type="text" required readonly>
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label  is-required">变更购买人：</label>
                <div class="col-sm-8">
                    <input name="agentTarNum" onclick="selectAgent()" readonly id="xagentName_Num" type="text" class="form-control" required>
                    <i class="fa fa-search" style="margin-top: -22px;margin-right:3px;float:right;"></i>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">备注：</label>
                <div class="col-sm-8">
                    <input name="note" class="form-control" id="note" type="text" required>
                </div>
            </div>

            <input name="laterPurchaser" class="form-control" id="xagentNum" type="hidden" required readonly>
            <input name="beforePurchaser" class="form-control" id="beforePurchaser" type="hidden" required readonly>

        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "formalPos/formalPos"
    $("#form-record-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        var formData = new FormData();
        formData.append("note",$("[name='note']").val());     //备注
        formData.append("beforePurchaser",$("[name='beforePurchaser']").val());   //更改前
        formData.append("laterPurchaser",$("[name='laterPurchaser']").val());   //更改后
        formData.append("file", $("[name = 'file']")[0].files[0]);

        if(formData.get("file") == "SN文件不能为空！"){
            $.modal.alertError();
            return
        }
        if(formData.get("beforePurchaser") == ""){
            $.modal.alertError("原购买人不能为空，请重新上传文件！");
            return
        }
        if(formData.get("laterPurchaser") == ""){
            $.modal.alertError("变更购买人不能为空！");
            return
        }
        if(formData.get("note") == ""){
            $.modal.alertError("备注不能为空！");
            return
        }
        $.ajax({
            url : prefix + "/addUpdatePurchaser",
            type: 'POST',
            data: formData,
            cache: false,
            contentType: false,
            processData: false,
            success : function(result) {
                $.modal.confirm(result.msg,function() {
                    $.modal.close()
                })
            },
            error : function(result) {
                $.modal.alertError(result.msg);
            }
        });

    }
    function selectAgent() {
        var url =ctx + "terminal/record" + "/selectAgentInfo";
        $.modal.open("选择服务商" , url, '800',"400");
    }

    function selectAgent2() {
        var url =ctx + "terminal/record" + "/selectAgentInfo2";
        $.modal.open("选择服务商" , url, '800',"400");
    }


</script>
</body>
</html>
